package com.power.ding.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;
import com.power.ding.model.Di_user;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 用户信息 持久层(hibernate)
 */

public interface Di_userDao extends JpaRepository<Di_user, Serializable>, JpaSpecificationExecutor<Di_user>, Repository<Di_user, Serializable>, Di_userDaoCustom<Di_user, Serializable> {

   @Modifying
   @Transactional
   @Query("delete  from Di_user s where  s.id in (:ids) ")
   void removeByIds(@Param("ids") List<Integer> ids);

   @Modifying
   @Transactional
   @Query(value =" select B.*,B.username as label, A.id as relationid, A.orgid as fId, A.ismain from di_userdept A join di_user B ON A.userid = B.id where A.rowstate >=0 and B.rowstate >=0", nativeQuery = true)
   List<Map<String,Object>> findAllDeptUser();


   @Query(value =" select * from Di_user s where s.mobile in (:phones) and s.rowstate >=0", nativeQuery = true)
   List<Di_user> findUserByPhones(@Param("phones") List<String> phones);

   /**
    * 根据手机号码查询审批端人员信息
    * @param mobile
    * @return
    */
   @Query(value =" select * from Ha_user s where s.mobile = :mobile", nativeQuery = true)
   Map findHa_userByMobile(String mobile);

   @Query(value =" select * from ha_user s where s.mobile= :mobile", nativeQuery = true)
   Map<String, Object> getSysUserByPhones(@Param("mobile") String mobile);

   @Query(value =" select * from std_admuser s where s.mobile= :mobile", nativeQuery = true)
   Map<String, Object> getRelUserByMobile(@Param("mobile") String mobile);

   @Query(value = "select * from Di_user s where s.userName like %:userName%",nativeQuery = true)
   List<Di_user> getUserByUserName(@Param("userName") String userName);

   @Query(value =" select * from Di_user s where s.id in (:ids)", nativeQuery = true)
   List<Di_user> findUserByIds(@Param("ids") List<String> ids);

}
